﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WPFZ80MapEditor"
    xmlns:converters="clr-namespace:WPFZ80MapEditor.ValueConverters"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="MainWindow"
    x:Name="MainWindow"
    Width="1280" Height="720" ResizeMode="CanResizeWithGrip" MinHeight="150" MinWidth="200" Background="White">
    
    <Window.Resources>
        
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ColorsAndStoryboards.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <converters:MainWindowTitleConverter x:Key="MainWindowTitleConverter"/>

        <Style x:Key="RadioButtonListItem" TargetType="{x:Type ListBoxItem}" >
        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="{x:Type ListBoxItem}">
        				<DockPanel LastChildFill="True" Background="{TemplateBinding Background}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="6,0" >
        					<RadioButton IsChecked="{TemplateBinding IsSelected}" Focusable="False" IsHitTestVisible="False" VerticalAlignment="Center" Margin="0,0,2,0" />
        					<ContentPresenter
        						Content             = "{TemplateBinding Content}"
        						ContentTemplate     = "{TemplateBinding ContentTemplate}"
        						ContentStringFormat = "{TemplateBinding ContentStringFormat}"
        						HorizontalAlignment = "{TemplateBinding HorizontalContentAlignment}"
        						VerticalAlignment   = "{TemplateBinding VerticalContentAlignment}"
        						SnapsToDevicePixels = "{TemplateBinding SnapsToDevicePixels}" />
        				</DockPanel>
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>
        </Style>

        <Style x:Key="RadioButtonList" TargetType="{x:Type ListBox}">

            <Style.Resources>
                <Style TargetType="{x:Type Label}">
                    <Setter Property="Padding" Value="0" />
                </Style>
            </Style.Resources>

        	<Setter Property="BorderThickness" Value="0" />
        	<Setter Property="Background"      Value="Transparent" />

        	<Setter Property="ItemContainerStyle" Value="{StaticResource RadioButtonListItem}" />

        	<Setter Property="Template">
        		<Setter.Value>
        			<ControlTemplate TargetType="{x:Type ListBox}">
        				<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
        			</ControlTemplate>
        		</Setter.Value>
        	</Setter>

            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="TextBlock.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                </Trigger>
            </Style.Triggers>

        </Style>

        <Style x:Key="HorizontalRadioButtonList" BasedOn="{StaticResource RadioButtonList}" TargetType="{x:Type ListBox}">
        	<Setter Property="ItemsPanel">
        		<Setter.Value>
        			<ItemsPanelTemplate>
        				<VirtualizingStackPanel Background="Transparent" Orientation="Horizontal" />
        			</ItemsPanelTemplate>
        		</Setter.Value>
        	</Setter>
        </Style>
        </ResourceDictionary>
    </Window.Resources>

    <Window.Title>
        <Binding Path="DataContext.Scenario" ElementName="MainWindow">
            <Binding.Converter>
                <StaticResource ResourceKey="MainWindowTitleConverter" />
            </Binding.Converter>
        </Binding>
    </Window.Title>

    <Window.CommandBindings>
        <CommandBinding Command="Undo"
                        CanExecute="UndoCanExecute"
                        Executed="UndoExecuted"/>
        <CommandBinding Command="Redo"
                        CanExecute="RedoCanExecute"
                        Executed="RedoExecuted"/>
        <CommandBinding Command="Open"
                        CanExecute="OpenCanExecute"
                        Executed="OpenExecuted"/>
        <CommandBinding Command="Save"
                        CanExecute="SaveCanExecute"
                        Executed="SaveExecuted"/>
    </Window.CommandBindings>

    <AdornerDecorator x:Name="TopLevelControl">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="Editing">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="StopButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SimulationPanelGridItem">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Testing">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="TilesSelectorGridItem">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ObjectSelectorGridItem">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="LayerListBox">
                            <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                        </BooleanAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="TestButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="SimulationPanelGridItem">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click" SourceName="TestButton">
                    <ei:GoToStateAction StateName="Testing"/>
                    <ei:CallMethodAction MethodName="StartTesting" TargetObject="{Binding ., ElementName=MainWindow}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="Click" SourceName="StopButton">
                	<ei:GoToStateAction StateName="Editing"/>
                    <ei:CallMethodAction MethodName="StopTesting" TargetObject="{Binding ., ElementName=MainWindow}"/>
                </i:EventTrigger>
                <i:EventTrigger>
                	<ei:GoToStateAction StateName="Editing"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <local:MapEditorControl x:Name="MapControl" />
            <DockPanel Panel.ZIndex="2">
				<Menu DockPanel.Dock="Top" x:Name="MainMenu" Height="20" Panel.ZIndex="1">
					<MenuItem Header="_File">
						<MenuItem Command="ApplicationCommands.New" />
						<MenuItem Command="ApplicationCommands.Open"/>
						<MenuItem Command="ApplicationCommands.Save"/>
						<MenuItem Header="E_xit" />
					</MenuItem>
					<MenuItem Header="_Edit">
						<MenuItem Command="Undo"/>
						<MenuItem Command="Redo"/>
						<Separator/>
                        <MenuItem Command="ApplicationCommands.Copy" />
                        <MenuItem Command="ApplicationCommands.Paste" />

					</MenuItem>
					<MenuItem Header="_Mapset" x:Name="MapsetMenu">
						<MenuItem x:Name="MapsetNew" Header="_New map" Click="MapsetNew_Click"/>
						<MenuItem x:Name="MapsetNewFromFile" Header="New map from _file..."/>
						<MenuItem x:Name="MapsetDelete" Header="_Delete map" Click="MapsetDelete_Click"/>
						<MenuItem Header="Add _column">
							<MenuItem Header="_Left" x:Name="AddColumnLeft"/>
							<MenuItem Header="_Right" x:Name="AddColumnRight"/>
						</MenuItem>
					</MenuItem>
					<MenuItem Header="_Map"/>
					<MenuItem Header="_View">
						<MenuItem x:Name="TilesMenuItem" Header="Show _tiles panel" IsCheckable="True" IsChecked="True"/>
						<MenuItem x:Name="PaddingMenuItem" Header="Show map _padding" IsCheckable="True" IsChecked="True"/>
                        <Separator/>
                        <MenuItem x:Name="ShowMiscLayerMenuItem" Header="Show misc layer" IsCheckable="True" IsChecked="True"/>
					</MenuItem>
					<MenuItem Header="_Help">
						<MenuItem Header="_About"/>
					</MenuItem>
				</Menu>

				<WrapPanel x:Name="ToolbarPanel" DockPanel.Dock="Top" Height="26" Panel.ZIndex="1" Background="White">
					<WrapPanel.Effect>
						<DropShadowEffect Direction="270" Opacity="0.25" ShadowDepth="5" />
					</WrapPanel.Effect>
					<ToolBar DockPanel.Dock="top" ToolBarTray.IsLocked="True" x:Name="MainToolBar" Height="26">
						<Button Command="ApplicationCommands.Open">
							<Image Source="Toolbar/open.bmp" OpacityMask="#A8E61D"/>
						</Button>
						<Button Command="ApplicationCommands.Save">
							<Image x:Name="image" Source="Toolbar/save.bmp"  OpacityMask="#A8E61D"/>
						</Button>
						<Button x:Name="TestButton" Content="Test"/>
						<Button x:Name="StopButton" Content="Stop"/>
						<Separator/>

						<ListBox x:Name="LayerListBox" Style="{StaticResource HorizontalRadioButtonList}" ItemContainerStyle="{StaticResource RadioButtonListItem}" SelectedValue="{Binding CurrentLayer}" SelectedValuePath="Tag">
							<ListBoxItem Tag="{x:Static local:LayerType.MapsetLayer}" Content="Mapset"/>
							<ListBoxItem Tag="{x:Static local:LayerType.TilegroupLayer}" Content="Tilegroup"/>
							<ListBoxItem Tag="{x:Static local:LayerType.MapLayer}" Content="Map"/>
							<ListBoxItem Tag="{x:Static local:LayerType.ObjectLayer}" Content="Objects"/>
							<ListBoxItem Tag="{x:Static local:LayerType.EnemyLayer}" Content="Enemies"/>
							<ListBoxItem Tag="{x:Static local:LayerType.MiscLayer}" Content="Misc"/>
                            <ListBoxItem Tag="{x:Static local:LayerType.ScriptLayer}" Content="Scripts"/>
						</ListBox>
					</ToolBar>
				</WrapPanel>

				<StatusBar DockPanel.Dock="Bottom" x:Name="StatusBar" Margin="0" Padding="0" Panel.ZIndex="1">
					<StatusBar.Effect>
						<DropShadowEffect Direction="90" Opacity="0.25" ShadowDepth="2" />
					</StatusBar.Effect>
					<StatusBarItem HorizontalAlignment="Left" >
						<WrapPanel Height="19" VerticalAlignment="Center">
							<Label Padding="0" VerticalContentAlignment="Bottom" VerticalAlignment="Bottom" Content="Tile:"/>
							<Rectangle Width="6"/>
							<Label Padding="0" Content="{Binding SelectedTile.TileIndex}"/>
						</WrapPanel>
					</StatusBarItem>
					<StatusBarItem>
						<TextBlock x:Name="StatusTextBlock" Text="{Binding Status}"/>
					</StatusBarItem>
					<StatusBarItem HorizontalAlignment="Right" Width="75">
						<ComboBox x:Name="ZoomLevelCombo" FontSize="10" SelectedIndex="0" Padding="8,2,0,3" Width="50" HorizontalAlignment="Right" IsEditable="False" IsTabStop="False" SelectionChanged="ZoomLevelCombo_SelectionChanged">
							<ComboBoxItem Content="100%" x:Name="CurrentZoomLevelItem"/>
							<ComboBoxItem Content="50%" />
							<ComboBoxItem Content="75%" />
							<ComboBoxItem Content="100%" />
							<ComboBoxItem Content="150%" />
							<ComboBoxItem Content="200%" />
							<ComboBoxItem Content="400%" />
						</ComboBox>
					</StatusBarItem>
				</StatusBar>

				<Grid x:Name="TilesSelectorGridItem" DockPanel.Dock="Left" Panel.ZIndex="2" Background="White" Width="170">
					<Grid.Effect>
						<DropShadowEffect Direction="0" Opacity="0.25" ShadowDepth="2" />
					</Grid.Effect>
					<local:TilesPanel x:Name="TileSelectorPanel"/>
				</Grid>

				<Grid x:Name="ObjectSelectorGridItem" DockPanel.Dock="Right" Panel.ZIndex="2" Background="White" Width="170">
					<Grid.Effect>
						<DropShadowEffect Direction="180" Opacity="0.25" ShadowDepth="2" />
					</Grid.Effect>
					<local:ObjectsPanel x:Name="ObjectsPanel"/>
				</Grid>

                <Grid x:Name="SimulationPanelGridItem" DockPanel.Dock="Right" Panel.ZIndex="2" Background="White" Width="170">
                    <Grid.Effect>
                        <DropShadowEffect Direction="180" Opacity="0.25" ShadowDepth="2" />
                    </Grid.Effect>
                    <local:SimulationPanel x:Name="SimulationPanel"/>
                </Grid>

                <Grid IsHitTestVisible="False"/>
			</DockPanel>
		</Grid>
	</AdornerDecorator>
</Window>
